package com.atguigu.tingshu.user.client;

import com.atguigu.tingshu.common.annotation.cache.Cache;
import com.atguigu.tingshu.common.annotation.login.LoginRequired;
import com.atguigu.tingshu.user.service.UserPaidTrackService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;

/**
 * <p>
 * 用户支付信息
 * </p>
 *
 * @author Haoran Sun
 * @since 2024/08/23
 */

@RestController
@RequestMapping("client/user/userPaid")
public class UserPaidClientController {

    @Resource
    private UserPaidTrackService userPaidTrackService;

    /**
     * 判断用户是否购买了专辑
     *
     * @param albumId 专辑id
     * @return 是否购买专辑
     */
    @GetMapping("isPaidAlbum/{albumId}")
    @Cache("cache:user:isPaidAlbum")
    @LoginRequired
    public Boolean isPaidAlbum(@PathVariable("albumId") Long albumId) {
        return userPaidTrackService.isPaidAlbum(albumId);
    }


    /**
     * 获取用户已购的音频id
     *
     * @param albumId 专辑id
     * @param userId  用户id
     * @return 用户已购的音频id
     */
    @GetMapping("/getPaidTrackIds/{albumId}/{userId}")
    @Cache("cache:user:getPaidTrackIds")
    public HashSet<Long> getPaidTrackIds(@PathVariable("albumId") Long albumId,
                                         @PathVariable("userId") Long userId) {
        return userPaidTrackService.getPaidTrackIds(albumId, userId);
    }

}
